package cz.hanis.android.pubaccounting.tools;

import java.util.ArrayList;
import java.util.List;

import cz.hanis.android.pubaccounting.model.Item;
import cz.hanis.android.pubaccounting.model.Pub;

public class DataHandler {

	private static DataHandler INSTANCE = null;
	
	private List<Pub> pubs;
	
	private DataHandler() {	
		pubs = new ArrayList<Pub>();
		crateTestPubs();
	}
	
	public static DataHandler getInstance() {
		if(INSTANCE == null) {
			INSTANCE = new DataHandler();
		}
		return INSTANCE;
	}	
	
	
	public String[] getPubsAsNameArray() {
		String[] array = new String[pubs.size()];
		int index = 0;
		for(Pub pub : pubs) {
			array[index++] = pub.getName();
		}
		return array;
	}
	
	public List<Pub> getPubList() {
		return pubs;
	}
	
	public Pub getPub(String name) {
		for(Pub pub : pubs) {
			if(pub.getName().equals(name)) {
				return pub;
			}
		}
		return null;
	}
	
	public void addPub(Pub pub) {
		pubs.add(pub);
	}
	
	public void modifyPub(Pub oldPub, Pub newPub) {
		oldPub.setName(newPub.getName());
	}
	
	
	private void crateTestPubs() {
		Pub prumyslovka = new Pub("Průmýslovka");
		prumyslovka.addItem(new Item("Radegast 10°", 23));
		prumyslovka.addItem(new Item("Radegast 12°", 26));
		prumyslovka.addItem(new Item("Starobrno 11°", 24));
		addPub(prumyslovka);		
		addPub(new Pub("Alterna"));
		addPub(new Pub("Pegas"));
		addPub(new Pub("Skála"));
		addPub(new Pub("Jam"));
		addPub(new Pub("Sausalito"));
		addPub(new Pub("Zelené dveře"));
		addPub(new Pub("Melodka"));
		addPub(new Pub("Tembo"));
		addPub(new Pub("U plaza"));
		addPub(new Pub("Plzeňský dvůr"));
		addPub(new Pub("A2"));
		
	}
	
	
	
	
	
	
}
